<?php

// +----------------------------------------------------------------------
// | 文件 UserActionWeightEvent.class.php
// +----------------------------------------------------------------------
// | 说明 用户操作权重获取的缓存配置
// +----------------------------------------------------------------------
// | 
// +----------------------------------------------------------------------
// | Author: 谢赤心 Legend. <xcx_legender@qq.com>
// +----------------------------------------------------------------------

namespace Api\Event\Cache;
use Api\Event\CacheEvent;

class UserActionWeightEvent implements ICacheEvent
{   

    const DB = 0;

    static public function set()
    {
        
    }

    static public function get()
    {
        $redis  = CacheEvent::instance(self::DB);
        $key    = 'IMBA.GLOBAL.USERACTIONWEIGHT';
        $config = $redis->get($key);
        if (!$config){
            $content = C('USER_ACTION_WEIGHT');
            if (!$content){
                return null;
            }

            $configures = explode("\r\n", $content);

            foreach ($configures as $value) {
                $items = explode(':', $value);
                $key = $items[0];
                $itemValue = explode(',', $items[1]);
                $config[$key] = [
                    intval($itemValue[0]),
                    intval($itemValue[1]),
                ];           
            }

            $config = serialize($config);
            $redis->setex($key, 3600, $config);
        }

        return $config ? unserialize($config) : null;
    }




}